/*     */ package com.cr.system.service.impl;
/*     */ 
/*     */ import com.cr.common.core.text.Convert;
/*     */ import com.cr.common.exception.ServiceException;
/*     */ import com.cr.common.utils.MyStringUtils;
/*     */ import com.cr.system.domain.SysPost;
/*     */ import com.cr.system.mapper.SysPostMapper;
/*     */ import com.cr.system.mapper.SysUserPostMapper;
/*     */ import com.cr.system.service.ISysPostService;
/*     */ import java.util.List;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Service;
/*     */ 
/*     */ @Service
/*     */ public class SysPostServiceImpl implements ISysPostService {
/*     */   @Autowired
/*     */   private SysPostMapper postMapper;
/*     */   
/*     */   @Autowired
/*     */   private SysUserPostMapper userPostMapper;
/*     */   
/*     */   public List<SysPost> selectPostList(SysPost post) {
/*  38 */     return this.postMapper.selectPostList(post);
/*     */   }
/*     */   
/*     */   public List<SysPost> selectPostAll() {
/*  49 */     return this.postMapper.selectPostAll();
/*     */   }
/*     */   
/*     */   public List<SysPost> selectPostsByUserId(Long userId) {
/*  61 */     List<SysPost> userPosts = this.postMapper.selectPostsByUserId(userId);
/*  62 */     List<SysPost> posts = this.postMapper.selectPostAll();
/*  63 */     for (SysPost post : posts) {
/*  65 */       for (SysPost userRole : userPosts) {
/*  67 */         if (post.getPostId().longValue() == userRole.getPostId().longValue())
/*  69 */           post.setFlag(true); 
/*     */       } 
/*     */     } 
/*  74 */     return posts;
/*     */   }
/*     */   
/*     */   public SysPost selectPostById(Long postId) {
/*  86 */     return this.postMapper.selectPostById(postId);
/*     */   }
/*     */   
/*     */   public int deletePostByIds(String ids) {
/*  98 */     Long[] postIds = Convert.toLongArray(ids);
/*  99 */     for (Long postId : postIds) {
/* 101 */       SysPost post = selectPostById(postId);
/* 102 */       if (countUserPostById(postId) > 0)
/* 104 */         throw new ServiceException(String.format("%1$s已分配,不能删除", new Object[] { post.getPostName() })); 
/*     */     } 
/* 107 */     return this.postMapper.deletePostByIds(postIds);
/*     */   }
/*     */   
/*     */   public int insertPost(SysPost post) {
/* 119 */     return this.postMapper.insertPost(post);
/*     */   }
/*     */   
/*     */   public int updatePost(SysPost post) {
/* 131 */     return this.postMapper.updatePost(post);
/*     */   }
/*     */   
/*     */   public int countUserPostById(Long postId) {
/* 143 */     return this.userPostMapper.countUserPostById(postId);
/*     */   }
/*     */   
/*     */   public String checkPostNameUnique(SysPost post) {
/* 155 */     Long postId = Long.valueOf(MyStringUtils.isNull(post.getPostId()) ? -1L : post.getPostId().longValue());
/* 156 */     SysPost info = this.postMapper.checkPostNameUnique(post.getPostName());
/* 157 */     if (MyStringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue())
/* 159 */       return "1"; 
/* 161 */     return "0";
/*     */   }
/*     */   
/*     */   public String checkPostCodeUnique(SysPost post) {
/* 173 */     Long postId = Long.valueOf(MyStringUtils.isNull(post.getPostId()) ? -1L : post.getPostId().longValue());
/* 174 */     SysPost info = this.postMapper.checkPostCodeUnique(post.getPostCode());
/* 175 */     if (MyStringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue())
/* 177 */       return "1"; 
/* 179 */     return "0";
/*     */   }
/*     */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\lib\creditorRights-system-4.7.0.jar!\com\cr\system\service\impl\SysPostServiceImpl.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */